package com.shuozi.keyboardpopup;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.library.baseAdapters.BR;

import android.app.Activity;
import android.content.Context;
import android.database.DatabaseUtils;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.shuozi.keyboardpopup.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity  implements View.OnFocusChangeListener {
    KeyboardPopupWindow keyboardPopupWindow ;
    Context context;
    Activity activity;
    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        context =this;
        activity=this;
        EditText editText=(EditText) findViewById(R.id.edit);
        EditText editText2=(EditText) findViewById(R.id.editText);
        EditText editText23=(EditText) findViewById(R.id.editText23);
        Button button=(Button) findViewById(R.id.button);
       // keyboardPopupWindow= new KeyboardWithCommit(this, this.getWindow().getDecorView(),editText , false);
        keyboardPopupWindow= new KeyboardPopupWindow(this, false,false);
        keyboardPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"点击啊",Toast.LENGTH_SHORT).show();
            }
        });
        KeyboardPopupHelper.addOnfoursListener(activity.getWindow().getDecorView(),this::onFocusChange);


        binding.setIswa(true);

    }

    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        keyboardPopupWindow.onFocusChange(view,hasFocus,activity.getWindow().getDecorView());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        KeyboardPopupHelper.releaseResources(keyboardPopupWindow);
    }
}
